<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style> 
   
    .box {
      width: 300px;
      padding: 30px 0;
      border: 1px solid #0f0;
    }
    .demo {
      width: 100px;
      height: 100px;
      margin: 0 auto;
      background-color: pink;
    }
      </style>
</head>
<body>
    
   <p>盒子水平居中</p>
   <div class="box">
    <div class="demo"></div>
  </div>
</body>
</html>